2 * This file is where we decide whether to initialise the Grade A run-time.
4 * - Beware: This file MUST parse without errors on even the most ancient of browsers!
5 * - Beware: Do not call mwNow before the isCompatible() check.
8 /* global mw, mwPerformance, mwNow, isCompatible, $VARS, $CODE */
10 window
.mwPerformance
= ( window
.performance
&& performance
.mark
) ? performance
: {
13 // Define now() here to ensure valid comparison with mediaWikiLoadEnd (T153819).
14 window
.mwNow
= ( function () {
15 var perf
= window
.performance
,
16 navStart
= perf
&& perf
.timing
&& perf
.timing
.navigationStart
;
17 return navStart
&& typeof perf
.now
=== 'function' ?
18 function () { return navStart
+ perf
.now(); } :
19 function () { return Date
.now(); };
23 * See <https://www.mediawiki.org/wiki/Compatibility#Browsers>
25 * Capabilities required for modern run-time:
27 * - DOM Level 4 & Selectors API Level 1
28 * - HTML5 & Web Storage
29 * - DOM Level 2 Events
31 * Browsers we support in our modern run-time (Grade A):
37 * - Mobile Safari 5.1+ (iOS 5+)
40 * Browsers we support in our no-javascript run-time (Grade C):
46 * - Mobile Safari 5.0+ (iOS 4+)
50 * - Symbian-based browsers
51 * - NetFront-based browser
53 * - Nokia's Ovi Browser
56 * - UC Mini (speed mode on)
58 * Other browsers that pass the check are considered Grade X.
60 * @param {string} [str] User agent, defaults to navigator.userAgent
61 * @return {boolean} User agent is compatible with MediaWiki JS
63 window
.isCompatible = function ( str
) {
64 var ua
= str
|| navigator
.userAgent
;
66 // http://caniuse.com/#feat=es5
67 // http://caniuse.com/#feat=use-strict
68 // http://caniuse.com/#feat=json / https://phabricator.wikimedia.org/T141344#2784065
71 return !this && !!Function
.prototype.bind
&& !!window
.JSON
;
74 // http://caniuse.com/#feat=queryselector
75 'querySelector' in document
&&
77 // http://caniuse.com/#feat=namevalue-storage
78 // https://developer.blackberry.com/html5/apis/v1_0/localstorage.html
79 // https://blog.whatwg.org/this-week-in-html-5-episode-30
80 'localStorage' in window
&&
82 // http://caniuse.com/#feat=addeventlistener
83 'addEventListener' in window
&&
85 // Hardcoded exceptions for browsers that pass the requirement but we don't want to
86 // support in the modern run-time.
87 // Note: Please extend the regex instead of adding new ones
89 ua
.match( /webOS\/1\.[0-4]|SymbianOS|Series60|NetFront|Opera Mini|S40OviBrowser|MeeGo|Android.+Glass|^Mozilla\/5\.0 .+ Gecko\/$|googleweblight/ ) ||
90 ua
.match( /PlayStation/i )
95 // Conditional script injection
98 if ( !isCompatible() ) {
99 // Undo class swapping in case of an unsupported browser.
100 // See ResourceLoaderClientHtml::getDocumentAttributes().
101 document
.documentElement
.className
= document
.documentElement
.className
102 .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
104 NORLQ
= window
.NORLQ
|| [];
105 while ( NORLQ
.length
) {
109 push: function ( fn
) {
114 // Clear and disable the other queue
124 * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
127 mw
.config
= new mw
.Map( $VARS
.wgLegacyJavaScriptGlobals
);
129 $CODE
.registrations();
131 mw
.config
.set( $VARS
.configuration
);
133 // Must be after mw.config.set because these callbacks may use mw.loader which
134 // needs to have values 'skin', 'debug' etc. from mw.config.
135 // eslint-disable-next-line vars-on-top
136 var RLQ
= window
.RLQ
|| [];
137 while ( RLQ
.length
) {
141 push: function ( fn
) {
146 // Clear and disable the other queue
153 window
.mediaWikiLoadStart
= mwNow();
154 mwPerformance
.mark( 'mwLoadStart' );
156 script
= document
.createElement( 'script' );
157 script
.src
= $VARS
.baseModulesUri
;
158 script
.onload
= script
.onreadystatechange = function () {
159 if ( !script
.readyState
|| /loaded|complete/.test( script
.readyState
) ) {
161 script
.onload
= script
.onreadystatechange
= null;
167 document
.getElementsByTagName( 'head' )[ 0 ].appendChild( script
);